#include "mainscene.h"
#include "ui_mainscene.h"
#include<QPainter>
#include"mypushbutton.h"
#include<QDebug>
#include<QTimer>
#include<QSound>
MainScene::MainScene(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainScene)
{
    ui->setupUi(this);
    setFixedSize(520,788);

    setWindowIcon(QIcon(":/res/Coin0001.png"));

    setWindowTitle("翻金币");

    //退出按钮
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });

    QSound* startSound=new QSound(":/res/TapButtonSound.wav",this);

    //开始按钮
    MyPushButton*startBtn=new MyPushButton(":/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);
    //实例化选择关卡场景
    chooseScene=new ChooseLevelScene;

    //监听选择关卡的选择按钮信号
    connect(chooseScene,&ChooseLevelScene::chooseSceneBack,this,[=](){
        chooseScene->hide();//将选择关卡场景隐藏
        this->show();//重新显示
    });

    connect(startBtn,&MyPushButton::clicked,[=](){
        //qDebug()<<"点击了开始";
        startSound->play();
        startBtn->zoom1();
        startBtn->zoom2();

        //延时进入
        QTimer::singleShot(500,this,[=](){
            //进入到选择关卡的场景中
            this->hide();
            chooseScene->show();
        });
    });


}


void MainScene::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);


    pix.load(":/res/Title.png");

    pix=pix.scaled(pix.width()*0.8,pix.height()*0.8);

    painter.drawPixmap(10,30,pix);
}

MainScene::~MainScene()
{
    delete ui;
}
